from django.db import models


# 用户表
class Auth_admin(models.Model):
    username = models.CharField('用户名', max_length=100)
    password = models.CharField('密码', max_length=100)
    head = models.CharField('头像地址', max_length=200)
    token = models.CharField('token', max_length=500)
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    out_time = models.TimeField(auto_now=True, auto_now_add=False)  # token 时间

    class Meta:
        db_table = 'auth_admin'


# 角色表
class Roles(models.Model):
    role_name = models.CharField('角色名称', max_length=100)  # 角色名称
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    update_time = models.DateTimeField(auto_now=True)  # 最后一次更新时间

    class Meta:
        db_table = 'roles'


# 用户角色关联表
class User_role(models.Model):
    user_id = models.ForeignKey(to=Auth_admin, on_delete=models.CASCADE)  # 关联到用户 ·
    role_id = models.ForeignKey(to=Roles, on_delete=models.CASCADE)  # 关联到角色 ·

    class Meta:
        db_table = 'user_role'


# 权限表
class Permissions(models.Model):
    per_name = models.CharField('权限名称', max_length=100)  # 权限名称(路由)
    pid = models.CharField('权限等级', max_length=20)  # 权限等级
    path = models.CharField('路由', max_length=100)  # 路由
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    update_time = models.DateTimeField(auto_now=True)  # 最后一次更新时间

    class Meta:
        db_table = 'permissions'


# 角色权限表
class Role_permissions(models.Model):
    role = models.ForeignKey(to=Roles, on_delete=models.CASCADE)  # 关联角色
    per_id = models.ForeignKey(to=Permissions, on_delete=models.CASCADE)  # 关联权限

    class Meta:
        db_table = 'role_permissions'

    # Create your models here.
